package com.project;

import com.project.servlet.AddServlet;
import com.project.servlet.InputServlet;
import com.project.servlet.TestServlet;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.Wrapper;
import org.apache.catalina.startup.Tomcat;

public class MainTomcat {
    public MainTomcat(){
        //产生tomcat对象
        Tomcat tomcat = new Tomcat();
        //设置启动端口
        tomcat.setPort(8088);
        //引导http引擎
        tomcat.getConnector();

        //创建上下文对象
        Context context = tomcat.addContext("",null);
        //注册servlet
        Wrapper w = Tomcat.addServlet(context,"testServlet",new TestServlet());
        w.setLoadOnStartup(1);
        //设置servlet访问路径
        w.addMapping("/lovo/*");

        Wrapper w1 = Tomcat.addServlet(context,"input",new InputServlet());
        w1.setLoadOnStartup(1);
        //设置servlet访问路径
        w1.addMapping("/input");

        Wrapper w2 = Tomcat.addServlet(context,"add",new AddServlet());
        w2.setLoadOnStartup(1);
        //设置servlet访问路径
        w2.addMapping("/add");

        try {
            //启动tomcat
            tomcat.start();
        } catch (LifecycleException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main(String[] args) {
        new MainTomcat();
    }
}
